import React from 'react'
import './User.less'
import { withRouter, Link } from 'react-router-dom'
class User extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            UserTitle: ['待付款', '已支付', '已发货', '评价', '退款/售后'],
            User: null
        }
    }
    goAddress = () => {
        this.props.history.push('/AllAddress/0/0/0/0/0/0/0')
    }
    componentDidMount() {
        this.$getData('/api/user/getUserMsg', params => {
            console.log(params)
            switch (params.code) {
                case 100:
                    this.setState({
                        User: params.data
                    })
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
    }
    render() {
        return (
            <div>
                {
                    this.state.User ? <div className='User'>
                        <div className='User-d1'>
                            <img className='User-d1-i1' src={require('../../static/img/erweima.png')} alt="" onClick={() => { this.props.history.push('/InviteCode') }} />
                            <div className='User-d2'>
                                <img className='User-d2-i1' src={this.state.User.atavar} alt="" />
                                <Link to='/Modify' className='User-d2-d1'>
                                    <div className='User-d2-d2'>
                                        <p>{this.state.User.nickName}</p>
                                        <img src={this.state.User.sex === 1 ? require('../../static/img/nan.png') : require('../../static/img/nv.png')} alt="" />
                                    </div>
                                    <p className='User-d2-p1'>欢迎来到中山市垕金电子商务！</p>
                                </Link>
                                <img className='User-d2-i2' src={require('../../static/img/right3.png')} alt="" />
                            </div>
                        </div>
                        <div className='User-d5 xin-center' onClick={() => { this.props.history.push('/Order/7') }}>
                            <p>我的订单</p>
                            <img src={require('../../static/img/right4.png')} alt="" />
                        </div>
                        <div className='User-d4 center'>
                            {
                                this.state.UserTitle.map((value, index) => (
                                    <Link to={index == 4 ? '/Refund' : `/Order/${index}`} key={value} className='center'>
                                        <img src={require(`../../static/img/User${index}.png`)} alt="" />
                                        <p>{value}</p>
                                    </Link>
                                ))
                            }
                        </div>
                        <Link to='/Account' className='User-d3 xin-center'>
                            <p>我的账户</p>
                            <img src={require('../../static/img/right4.png')} alt="" />
                        </Link>
                        <Link to='/'>
                            <img src={require("../../static/img/hehuoren.png")} alt="" />
                        </Link>
                        <div className='User-d3 xin-center' onClick={this.goAddress}>
                            <p>地址管理</p>
                            <img src={require('../../static/img/right4.png')} alt="" />
                        </div>
                        <div className='User-d3 xin-center'>
                            <p>联系客服</p>
                            <img src={require('../../static/img/right4.png')} alt="" />
                        </div>
                        <div className='User-d3 xin-center'>
                            <p>退出登录</p>
                            <img src={require('../../static/img/right4.png')} alt="" />
                        </div>
                    </div> : <div></div>
                }</div>
        )
    }
}

export default withRouter(User)